﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WMS.FC.Domain.PersistenceObject.Business;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.POConfig.Business
{
    public class JobConfig : POBaseConfig<JobPO>
    {
        public override void InitializeData(EntityTypeBuilder<JobPO> builder)
        {
        }

        public override void MapColumn(EntityTypeBuilder<JobPO> builder, ref int index)
        {
            builder.HasComment("定时任务表");
            builder.Property(entity => entity.Code).ConfigColumn("CODE", "编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.Group).ConfigColumn("GROUP", "组名", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.Description).ConfigColumn("DESCRIPTION", "描述", 200).HasColumnOrder(index++);
            builder.Property(entity => entity.Expression).ConfigColumn("EXPRESSION", "表达式", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.Url).ConfigColumn("URL", "接口地址", 200, true).HasColumnOrder(index++);
            builder.Property(entity => entity.WarehouseCode).ConfigColumn("WAREHOUSE_CODE", "仓库编码", 50, true).HasColumnOrder(index++);
        }

        public override void MapIndex(EntityTypeBuilder<JobPO> builder)
        {
            builder.HasIndex(entity => new { entity.Code, entity.Group, entity.WarehouseCode }).HasDatabaseName($"UN_{TableName}_1").IsUnique();
        }
    }
}
